package mn.more.wits.server.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;

/**
 * @author <a href="mailto:mike.liu@aptechmongolia.edu.mn">Mike Liu</a>
 * @version $Revision: 119 $
 */
public final class AccountStatus implements Serializable {

	private static final HashMap<Integer, AccountStatus> ACCOUNT_STATUSES = new HashMap<Integer, AccountStatus>();

	public static final AccountStatus ACTIVE = new AccountStatus(0, "ACTIVE");
	public static final AccountStatus INACTIVE = new AccountStatus(1, "INACTIVE");
	public static final AccountStatus DISABLED = new AccountStatus(2, "DISABLED");

	private int status;
	private String description;

	public AccountStatus() {}

	private AccountStatus(int status, String description) {
		this.status = status;
		this.description = description;
		ACCOUNT_STATUSES.put(status, this);
	}

	public int getStatus() { return status; }

	public String getDescription() { return description; }

	public String toString() { return status + ":" + description; }

	public static AccountStatus getAccountStatus(int status) { return ACCOUNT_STATUSES.get(status); }

	public static AccountStatus getAccountStatus(String description) {
		Collection<AccountStatus> values = ACCOUNT_STATUSES.values();
		for (AccountStatus status : values) {
			if (status.description.equals(description)) { return status; }
		}

		return null;
	}
}
